package edu.nf.redismqes.web;

import edu.nf.redismqes.common.VO.ResultVO;
import edu.nf.redismqes.common.base.BaseController;
import edu.nf.redismqes.model.entity.New;
import edu.nf.redismqes.service.NewProduceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @ Author bin
 * @ Create  2025/10/21 下午7:06
 **/
@RestController
@RequestMapping("/news")
public class NewsController extends BaseController {
    @Autowired
    private NewProduceService newProduceService;


    @PostMapping ("/publish")
    public ResultVO publish(@RequestBody New news){
        newProduceService.addNews(news);
        return success();
    }

    @PostMapping ("/update")
    public ResultVO update(@RequestBody New news){
        newProduceService.updateNews(news);
        return success();
    }

    @PostMapping ("/delete")
    public ResultVO delete(@RequestParam("newsId") Integer newsId){
        newProduceService.delNews(newsId);
        return success();
    }

    /**
     * 分页查询
     * */
    @PostMapping ("/list")
    public ResultVO<List<New>> list(@RequestParam("pageNum") Integer pageNum, @RequestParam("pageSize") Integer pageSize){
        List<New> news = newProduceService.list(pageNum, pageSize);
        return success(news);
    }

    /**
     * 高亮查询
     * */
    @PostMapping ("/search")
    public ResultVO<List<New>> search(@RequestParam("keyword") String keyword){
        List<New> news = newProduceService.search(keyword);
        System.out.println("新闻搜索结果" + news.toString());
        return success(news);
    }

    /**
     * 通过id查询新闻详情
     * */
    @PostMapping ("/getNewsById")
    public ResultVO<New> getNewsById(@RequestParam("newsId") Integer newsId){
        New news = newProduceService.getNewsById(newsId);
        return success(news);
    }


}
